package com.cyx.gametool.cons;

import lombok.Getter;
import lombok.Setter;

/**
 * 状态码为0表示成功
 * 状态码为 >=100 表示错误
 * 状态码为1-99 表示失败
 */
public class Result {

    // 自定义状态码
    @Getter
    @Setter
    private int code;

    // 自定义状态信息
    @Getter
    @Setter
    private String message;

    // 自定义参数
    @Getter
    @Setter
    private Object data;

    public Result() {
    }

    public Result(int code) {
        this.code = code;
    }

    public static Result error() {
        return new Result(1);
    }

    public static Result success() {
        return new Result(0);
    }

    public static Result fail() {
        return new Result(100);
    }

    public boolean isSuccess() {
        return 0 == code;
    }

    public boolean isFail() {
        return 0 < code && code < 100;
    }

    public boolean isError() {
        return 100 <= code;
    }
}
